package top.lwaiting.mapper;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import top.lwaiting.domain.Order;
import top.lwaiting.domain.User;

import java.util.List;

/**
 * @author YANG
 * @version V1.0
 * @date 2024/1/26 16:22
 * @see IOrderMapper
 **/
public interface IOrderMapper {

    /**
     * MyBatis 复杂映射一对一
     * 查询订单的同时还查询该订单所属的用户
     * @return {@link Order}
     */
    public List<Order> findOrderAndUser();

    /**
     * MyBatis 复杂映射一对一
     * 注解实现
     * 查询订单的同时还查询该订单所属的用户
     * @return {@link Order}
     */
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "orderTime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid",
                    javaType = User.class,
                    one = @One(select = "top.lwaiting.mapper.IUserMapper.selectUserById"))
    })
    @Select("SELECT * FROM orders")
    public List<Order> findOrderAndUserAnnotation();

    /**
     * 根据用户Id查询订单信息
     * @param uid
     * @return
     */
    @Select("SELECT * FROM orders WHERE uid = #{uid}")
    public List<Order> findOrderByUid(Integer uid);

}
